package LeetCode.leetcode;

/**
 * 第一个错误的版本
 * @author: leiwenkang02@meituan.com
 * @date: 2018/8/27
 * @time: 20:24
 */
public class Test278第一个错误的版本 {
    public static void main(String[] args) {
        System.out.println(firstBadVersion(8));
    }
    public static int firstBadVersion(int n) {
        int start = 1;
        int end = n;

        while (start <= end) {
            int mid = (start + end) >>> 1;
            if (isBadVersion(mid)) {
                if (!isBadVersion(mid - 1) || mid == 1) {
                    return mid;
                } else {
                    end = mid - 1;
                }
            } else {
                start = mid + 1;
            }
        }
        return -1;

    }

    public static boolean isBadVersion(int version) {
        if (version > 6) {
            return true;
        }
        return false;
    }
}
